<template>
  <!-- 弹窗 -->
  <el-dialog v-model="dialogVisible" title="添加角色" width="60%">
    <el-form :model="role">
      <el-form-item label="角色名称" :label-width="formLabelWidth" required>
        <el-input v-model="role.roleName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="角色描述" :label-width="formLabelWidth" required>
        <el-input v-model="role.roleDesc" autocomplete="off" />
      </el-form-item>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="getConfirm">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
// 控制弹出窗显示
const dialogVisible = ref(false);
const formLabelWidth = "110px";

const role = reactive({
  roleName: "",
  roleDesc: "",
});

const emit = defineEmits(["getAddConfirm"]);

// 打开弹窗
const addDialog = () => {
  dialogVisible.value = true;
};

// 将子组件方法暴露出去
defineExpose({
  addDialog,
});

// 添加角色确认
const getConfirm = () => {
  dialogVisible.value = false;
  emit("getAddConfirm", role);
  // 确认后重置
  role.roleName = "";
  role.roleDesc = "";
};
</script>
